package com.spzx.channel.service.imp;

import com.spzx.channel.service.IIndexService;
import com.spzx.common.core.constant.SecurityConstants;
import com.spzx.common.core.domain.R;
import com.spzx.common.core.exception.ServiceException;
import com.spzx.product.api.RemoteCategoryService;
import com.spzx.product.api.RemoteProductService;
import com.spzx.product.api.domain.vo.CategoryVo;
import com.spzx.product.api.domain.vo.ProductSku;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service

public class IndexServiceImp implements IIndexService {

    @Resource
    RemoteCategoryService remoteCategoryService;
    @Resource
    RemoteProductService remoteProductService;


    @Override
    public Map<String, Object> getIndexData() {
        R<List<CategoryVo>> category = remoteCategoryService.getOneCategory(SecurityConstants.INNER);
        if (R.FAIL == category.getCode()) {
            throw new ServiceException(category.getMsg());
        }
        R<List<ProductSku>> topSale = remoteProductService.getTopSale(SecurityConstants.INNER);

        if (R.FAIL == topSale.getCode()) {
            throw new ServiceException(topSale.getMsg());
        }


        Map<String,Object> map=new HashMap<>();
        map.put("productSkuList",topSale.getData());
        map.put("categoryList",category.getData());
        return map;
    }
}
